class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
        self.pre = None

    def __init__(self, val=0, next=None, pre=None):
        self.val = val
        self.next = next
        self.pre = pre


class LinkedList:
    def __init__(self):
        self.head = ListNode(-1)
        self.tail = ListNode(-1)
        self.head.next = self.tail
        self.tail.pre = self.head

    def is_empty(self):
        return self.head.next == self.tail

    # 尾插
    def add_node(self, val):
        node = ListNode(val)
        node.pre = self.tail.pre
        self.tail.pre.next = node
        node.next = self.tail
        self.tail.pre = node

    def delete_node_by_value(self, val):
        cur = self.head.next
        while cur != self.tail:
            if cur.val == val:
                self.delete_node(cur)
            cur = cur.next
        return None

    def delete_node(self, node: ListNode):
        node.pre.next = node.next
        node.next.pre = node.pre

    def print(self):
        cur = self.head.next
        while cur != self.tail:
            print(cur.val, end=",")
            cur = cur.next


if __name__ == "__main__":
    linkedList = LinkedList()
    for i in range(10):
        linkedList.add_node(i)

    linkedList.print()
    print(linkedList.is_empty())
    linkedList.delete_node_by_value(5)
    linkedList.print()
